package littlewhisker.communication {
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLLoader;
	import flash.events.Event;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	/**
	 * @author Philip
	 */
	public class RequestURL {
		
		public static const _blank:String = "_blank";
		public static const _self:String = "_self";
		public static const _top:String = "_top";
		public static const _parent:String = "_parent";
		
		public static function gotoURL(url:String, target:String = _blank,data:* = null, method:String = "") : void {
			
			var request : URLRequest = new URLRequest(url);
			
    		if(data) request.data = data;
			if(method) request.method = method;
            try {            
               navigateToURL(request); 
            }
            catch (e:Error) {	   
            	
            }
		}
		
		public static function sendAndLoad(url:String,data:* = null, method:String = "", callback:Function = null) : void {
			var request : URLRequest = new URLRequest(url);
			request.contentType = "text/xml";
			request.method = URLRequestMethod.POST;
    		if(data) request.data = data;
			if(method) request.method = method;
    	 	
          	var loader:URLLoader = new URLLoader (request);
		
			if (callback!=null) loader.addEventListener(Event.COMPLETE, callback);
			loader.dataFormat = URLLoaderDataFormat.TEXT;
			loader.load(request);
		}
		
		
		
	}
}



				

